<template>
	<view>
		<!-- 	<cu-custom bgColor="bg-gradual-primary" :isBack="true">
			<block slot="backText">返回</block>
			<block slot="content">备注</block>
		</cu-custom> -->
		<view style="padding: 15rpx;">
			<view class="calendar-remark">
				<textarea v-model="remark" placeholder="填写备注..." maxlength=500 style="height: 100%; width: 100%;" />
				</view>
		
		</view>
		
		<button class="flex cu-btn round justify-center margin-xl bg-primary" @click="addOrUpdateRemark()">
			保存
		</button>
		
	</view>
</template>

<script>
		import helper from '../../../common/helper.js';
		import Bus from '../../../common/bus.vue';
	export default {
		data() {
			return {
				remark:'',
				monthDay:'',
				userId:'',
			};
		},
		onLoad: function(option) { //option为object类型，会序列化上个页面传递的参数
			console.log(option.from)
		
			//区分是从哪来的
			this.remark = option.remark;
			this.monthDay = option.monthDay;
			this.userId = option.userId;
			
		
		
		},
		methods:{
			// 调用服务器
			addOrUpdateRemark() {
			
				let that = this;
				let playod = {
					userId: that.userId,
					monthDay: that.monthDay,
					remark: that.remark
				};
			
				uni.showLoading({
					title: "加载中"
				});
				uni.request({
					url: helper.api + '/appYmrecord/open/addOrUpdateRemark', //仅为示例，并非真实接口地址。
					method: 'get',
					data: playod,
					header: {
						'Content-Type': 'application/json' //自定义请求头信息
					},
					complete() {
						uni.hideLoading();
					},
					success: (res) => {
						console.log(res.data);
			
						if (res.data.code === 0) {
							
							uni.showToast({
								title: "操作成功！",
								duration: 1000
							});
							setTimeout(function()  {
							 
							   Bus.$emit('calendarRemark', "fromCalendarRemark");
							 
							   }, 1000);
							
			
							// todo 刷新数据
						} else {
							uni.showModal({
								title: '请求失败！',
								content: '错误原因:' + res.data.msg,
								showCancel: false
							});
							return;
						}
					},
					fail: (err) => {
						uni.showModal({
							title: '请求失败！',
							content: '错误原因:' + err,
							showCancel: false
						});
					}
				});
			}
		}
	}
</script>

<style lang="scss">
	
	.calendar-remark {
		width: 100%;
		height: 300rpx;
		padding: 15rpx;
		border: 1px solid;
		margin-top: 50rpx;
		border-radius: 5px;
		border-color: $uni-color-primary;
		color: $uni-text-color;
	
	}

</style>
